var express = require('express');
const connection = require('../db/sql');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});
//查询商品数据接口
router.get('/api/goods/shopList',function(req,res,next){
  //前端给后端的数据
  let [searchName,orderName] = Object.keys(req.query);
  let [name,order] = Object.values(req.query);
  // console.log(req.query);
  // console.log('select * from goods_list where name like "%' + name + '%" order by '+ orderName +' ' + order +'');
  connection.query('select * from goods_list where name like "%' + name + '%" order by '+ orderName +' ' + order +'' ,(error,result)=>{
    // console.log(result);
    res.send({
      code:0,
      data:result
    })
  })
})

//首页大红袍数据
router.get('/api/index_List/1/data/1', function(req, res, next) {
  res.send({
    code:0,
    data:[
      {
        id:0,
        type:'adList',
        data:[
          {
            id:1,
            imgUrl:'./images/dhp.jpeg'
          },
          {
            id:1,
            imgUrl:'./images/dhp.jpeg'
          },
          {
            id:1,
            imgUrl:'./images/dhp.jpeg'
          }
        ]
      },
      //猜你喜欢
      {
        id:1,
        type:'likeList',
        data:[
          {
              id:1,
              imgUrl:'./images/like.jpeg',
              name:'喀什角动量卡机离开家数据库打开了',
              price:'299'
          },
          {
              id:2,
              imgUrl:'./images/like.jpeg',
              name:'喀什角动量卡机离开家',
              price:'299'
          },
          {
              id:3,
              imgUrl:'./images/like.jpeg',
              name:'喀什角动量卡机离开家',
              price:'299'
          },
          {
              id:4,
              imgUrl:'./images/like.jpeg',
              name:'喀什角动量卡机离开家',
              price:'299'
          }
        ]
      }
    ]
  });
});
//首页推荐数据
router.get('/api/index_List/0/data/1', function(req, res, next) {
  res.send({
      code:0,
      data:{
        topBar:[
          {id:0,label:'推荐'},
          {id:1,label:'大红袍'},
          {id:2,label:'铁观音'},
          {id:3,label:'绿茶'},
          {id:4,label:'普尔'},
          {id:5,label:'茶具'},
          {id:6,label:'花茶'},
          {id:7,label:'龙井茶'},
          {id:8,label:'白茶'},
        ],
        data:[
          {
            id:0,
            type:'swiperList',
            data:[
              {id:0,imgUrl:'./images/swiper1.jpeg'},
              {id:0,imgUrl:'./images/swiper2.jpeg'},
              {id:0,imgUrl:'./images/swiper3.jpeg'}
            ]
          },
          {
            id:1,
            type:'iconsList',
            data:[
              {id:0,title:'自饮茶',imgUrl:'./images/icons1.png'},
              {id:1,title:'茶具',imgUrl:'./images/icons2.png'},
              {id:2,title:'茶礼盒',imgUrl:'./images/icons3.png'},
              {id:3,title:'领福利',imgUrl:'./images/icons4.png'},
              {id:4,title:'官方验证',imgUrl:'./images/icons5.png'}
            ]
          },
          //爆款推荐
          {
            id:2,
            type:'recommendList',
            data:[
              {
                  id:1,
                  name:'龙井1号铁罐250克',
                  content:'鲜爽甘醇 口粮首选',
                  price:'68',
                  imgUrl:'./images/recommend.jpeg'
              },
              {
                  id:2,
                  name:'龙井1号铁罐250克',
                  content:'鲜爽甘醇 口粮首选',
                  price:'68',
                  imgUrl:'./images/recommend.jpeg'
              }
            ]
          },
          //猜你喜欢
          {
            id:3,
            type:'likeList',
            data:[
              {
                  id:1,
                  imgUrl:'./images/like.jpeg',
                  name:'喀什角动量卡机离开家数据库打开了',
                  price:'299'
              },
              {
                  id:2,
                  imgUrl:'./images/like.jpeg',
                  name:'喀什角动量卡机离开家',
                  price:'299'
              },
              {
                  id:3,
                  imgUrl:'./images/like.jpeg',
                  name:'喀什角动量卡机离开家',
                  price:'299'
              },
              {
                  id:4,
                  imgUrl:'./images/like.jpeg',
                  name:'喀什角动量卡机离开家',
                  price:'299'
              },
              {
                  id:5,
                  imgUrl:'./images/like.jpeg',
                  name:'喀什角动量卡机离开家数据库打开了',
                  price:'299'
              },
              {
                  id:6,
                  imgUrl:'./images/like.jpeg',
                  name:'喀什角动量卡机离开家',
                  price:'299'
              },
              {
                  id:7,
                  imgUrl:'./images/like.jpeg',
                  name:'喀什角动量卡机离开家',
                  price:'299'
              },
              {
                  id:8,
                  imgUrl:'./images/like.jpeg',
                  name:'喀什角动量卡机离开家',
                  price:'299'
              },
              {
                  id:9,
                  imgUrl:'./images/like2.jpeg',
                  name:'喀什角动量卡机离开家数据库打开了',
                  price:'299'
              },
              {
                  id:10,
                  imgUrl:'./images/like2.jpeg',
                  name:'喀什角动量卡机离开家',
                  price:'299'
              },
              {
                  id:11,
                  imgUrl:'./images/like2.jpeg',
                  name:'喀什角动量卡机离开家',
                  price:'299'
              },
              {
                  id:12,
                  imgUrl:'./images/like2.jpeg',
                  name:'喀什角动量卡机离开家',
                  price:'299'
              },
              {
                  id:13,
                  imgUrl:'./images/like3.jpeg',
                  name:'喀什角动量卡机离开家数据库打开了',
                  price:'299'
              },
              {
                  id:14,
                  imgUrl:'./images/like3.jpeg',
                  name:'喀什角动量卡机离开家',
                  price:'299'
              },
              {
                  id:15,
                  imgUrl:'./images/like3.jpeg',
                  name:'喀什角动量卡机离开家',
                  price:'299'
              },
              {
                  id:16,
                  imgUrl:'./images/like3.jpeg',
                  name:'喀什角动量卡机离开家',
                  price:'299'
              }
            ]
          },
        ]
      }
  })
});
module.exports = router;
